import React, { Component } from 'react'
import './index.less'
import LoginForm from './loginForm'
import Http from '../../axios'

export default class index extends Component {

  componentDidMount() {
    if (window.localStorage.getItem('remember')) {
      const data = JSON.parse(window.localStorage.getItem('userInfo'));
      this.onLogin({userName: data.username, password: data.value})
    }
  }

  onLogin = (values) => {
    Http.request({
      url: '/login/user_login_check_pst',
      method: 'post',
      data: {
        username: values.userName,
        value: values.password
      }
    }).then((resData) => {
      window.localStorage.setItem('remember', values.remember);
      window.localStorage.setItem('userInfo', JSON.stringify(resData.data));
      this.props.history.push('/home/culture');
    })
  }
  
  render() {
    return (
      <section className="login">
        <div className="login-body">
          <span className="login-title">西南家网</span>
          <div className="login-contnet">
            <LoginForm onLogin={this.onLogin}></LoginForm>
          </div>
        </div>
      </section>
    )
  }
}
